/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <flgrCoreMalloc.h>
#include <flgrCoreDispatch.h>
#include <flgrCoreVector.h>
#include "flgrDataToolsPStack.h"


/*!
 * \defgroup group_fulguro_datatools_pstack Priority Stack
 * \brief Priority Stack
 * \ingroup group_fulguro_datatools
 * @{
 */




//////////////////////////////////////////////////////////////////
/*! Allocate the PriorityStack structure
 *  \code
 *  //This function is used to insert (odered) Stack in the PStack stack list
 *  //This compare function example use norm to choose which vector is inferior
 *  #include <flgrCoreVector.h>
 *  #include <flgrCoreMeasureVector.h>
 *  #include <flgrCoreArithVector.h>
 *
 *  {...}
 *
 *  int myComparePriorityLabel(FLGR_Vector *priorityLabel1, FLGR_Vector *priorityLabel2) {
 *    FLGR_Vector vec_float64 = flgr_vector_create(priorityLabel1->spp, FLGR_FLOAT64);
 *    fgFLOAT64 vol1, vol2;
 *
 *    flgr_vector_copy(vec_float64, priorityLabel1);
 *    flgr_vector_square(vec_float64, vec_float64);
 *    flgr_vector_measure_volume(vec_float64, &vol1);
 *
 *    flgr_vector_copy(vec_float64, priorityLabel2);
 *    flgr_vector_square(vec_float64, vec_float64);
 *    flgr_vector_measure_volume(vec_float64, &vol2);
 *
 *    flgr_vector_destroy(vec_float64);
 *
 *    if(vol1>vol2)
 *      return FLGR_TRUE;
 *    
 *    return FLGR_FALSE;
 *  }
 *  \endcode 
 *  @param type : data type
 *
 *
 *  @param fcompare : function to compare two vector (needed to set and ordered relationship)
 *  @returns a pointer to FLGR_PStack
 *
 *  
 */
//////////////////////////////////////////////////////////////////
FLGR_PStack *flgr_pstack_create(FLGR_Type type, FLGR_VectorCompare fcompare) {
  FLGR_PStack *pstk = (FLGR_PStack *) flgr_malloc(sizeof(FLGR_PStack));

  FLGR_DECLARE_FUNCTION;
  
  if(pstk==NULL) {
    POST_ERROR("Could not allocate data\n");
    return NULL;
  }

  pstk->nbPriority = 0;
  pstk->first = NULL;
  pstk->last = NULL;
  pstk->type = type;
  pstk->compareStackFunction = fcompare;

  return pstk;

}


//////////////////////////////////////////////////////////////////
/*! Unallocate the PriorityStack structure
 *  @param pstack : a pointer to FLGR_PStack
 *  @returns a pointer
 */
//////////////////////////////////////////////////////////////////
void flgr_pstack_destroy(FLGR_PStack *pstack) {
  FLGR_McStack *stack = pstack->first;
  FLGR_McStack *stknext;
  int row, col;

   FLGR_DECLARE_FUNCTION;
  
 if(pstack==NULL) {
    POST_ERROR("Null objects!\n");
    return;
  }

  while(stack != NULL) {

    while(stack->size!=0) {
      flgr_pstack_pop_stack(stack,&row,&col);
    }

    stknext = stack->next;
    flgr_vector_destroy(stack->priorityLabel);
    flgr_free(stack);
    stack = stknext;
  }
}







////////////////////////////////////////////////////////////////////////
// Macro for different type of flgr_pstack_push
////////////////////////////////////////////////////////////////////////
#define PSTACK_PUSH(dtype)						\
  FLGR_McStack *stack;							\
  FLGR_Ret ret;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  stack = flgr_pstack_get_stack_##dtype(pstack, priorityLabel);		\
									\
  if(stack == NULL) {							\
    stack = flgr_pstack_create_stack_##dtype(pstack, priorityLabel);	\
    if(stack == NULL) {							\
      POST_ERROR("Could not create the stack for priority!\n");		\
      return FLGR_RET_ALLOCATION_ERROR;					\
    }									\
  }									\
  ret = flgr_pstack_push_stack(stack, row, col);			\
									\
  return ret

FLGR_Ret flgr_pstack_push_fgBIT(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  flgr_no_define_type_function(FLGR_BIT);
  return FLGR_RET_NOT_IMPLEMENTED;
}
FLGR_Ret flgr_pstack_push_fgUINT8(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  PSTACK_PUSH(fgUINT8);
}
FLGR_Ret flgr_pstack_push_fgUINT16(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  PSTACK_PUSH(fgUINT16);
}
FLGR_Ret flgr_pstack_push_fgUINT32(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  PSTACK_PUSH(fgUINT32);
}
FLGR_Ret flgr_pstack_push_fgINT8(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  PSTACK_PUSH(fgINT8);
}
FLGR_Ret flgr_pstack_push_fgINT16(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  PSTACK_PUSH(fgINT16);
}
FLGR_Ret flgr_pstack_push_fgINT32(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  PSTACK_PUSH(fgINT32);
}
FLGR_Ret flgr_pstack_push_fgFLOAT32(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  PSTACK_PUSH(fgFLOAT32);
}
FLGR_Ret flgr_pstack_push_fgFLOAT64(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  PSTACK_PUSH(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! Push pixel coordinates in the Priority stack.
 *  If the corresponding stack for a given priority doesn't exist, the stack will be created and added to the priority stack
 *  @param pstack : pointer on a FLGR_PStack structure
 *  @param priorityLabel : a pointer to a integer for label value of the stack to push pixel coordinates
 *  @param row : integer for coordinates
 *  @param col : integer for coordinates
 *  @returns a pointer
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr_pstack_push(FLGR_PStack *pstack, FLGR_Vector *priorityLabel, int row, int col) {
  FLGR_DECLARE_FUNCTION;
  
  if(pstack==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }
  
  FLGR_DISPATCH_FUNCTION(FLGR_RET_TYPE_UNKNOWN,pstack->type,flgr_pstack_push, pstack, priorityLabel, row, col);

}




//////////////////////////////////////////////////////////////////
/*! Pop pixel coordinates from a stack
 *  @param stack : pointer on a FLGR_McStack structure
 *  @param row : integer for coordinates
 *  @param col : integer for coordinates
 *  @returns a pointer
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr_pstack_pop_stack(FLGR_McStack *stack, int *row, int *col) {
  FLGR_McStackLink *tmp = stack->top;

  FLGR_DECLARE_FUNCTION;
  
  if(stack==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(tmp==NULL) {
    *row = 0;
    *col = 0;
    return FLGR_RET_OK;
  }

  *row = tmp->row;
  *col = tmp->col;

  stack->top = tmp->lower;
  stack->size--;

  flgr_free(tmp);

  return FLGR_RET_OK;
}

//////////////////////////////////////////////////////////////////
/*! Push pixel coordinates in a stack
 *  @param stack : pointer on a FLGR_McStack structure
 *  @param row : integer for coordinates
 *  @param col : integer for coordinates
 *  @returns a pointer
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr_pstack_push_stack(FLGR_McStack *stack, int row, int col) {
  FLGR_McStackLink *tmp = (FLGR_McStackLink*) flgr_malloc(sizeof(FLGR_McStackLink));

  FLGR_DECLARE_FUNCTION;
  
  if(stack==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(tmp==NULL) return FLGR_RET_ALLOCATION_ERROR;

  tmp->lower = stack->top;
  stack->top = tmp;
  stack->size++;

  tmp->row = row;
  tmp->col = col;

  return FLGR_RET_OK;
}



////////////////////////////////////////////////////////////////////////
// Macro for different types flgr_pstack_check_stack_priority
////////////////////////////////////////////////////////////////////////
#define FLGR_MACRO_PSTACK_SET_STACK_PRIORITY(dtype)			\
  FLGR_DECLARE_FUNCTION;						\
									\
  flgr_vector_copy_##dtype##_##dtype(stack->priorityLabel,		\
				     priorityLabel)

void flgr_pstack_set_stack_priority_fgBIT(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  flgr_no_define_type_function(FLGR_BIT); 
}
void flgr_pstack_set_stack_priority_fgUINT8(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_MACRO_PSTACK_SET_STACK_PRIORITY(fgUINT8);
}
void flgr_pstack_set_stack_priority_fgUINT16(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_MACRO_PSTACK_SET_STACK_PRIORITY(fgUINT16);
}
void flgr_pstack_set_stack_priority_fgUINT32(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_MACRO_PSTACK_SET_STACK_PRIORITY(fgUINT32);
}
void flgr_pstack_set_stack_priority_fgINT8(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_MACRO_PSTACK_SET_STACK_PRIORITY(fgINT8);
}
void flgr_pstack_set_stack_priority_fgINT16(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_MACRO_PSTACK_SET_STACK_PRIORITY(fgINT16);
}
void flgr_pstack_set_stack_priority_fgINT32(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_MACRO_PSTACK_SET_STACK_PRIORITY(fgINT32);
}
void flgr_pstack_set_stack_priority_fgFLOAT32(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_MACRO_PSTACK_SET_STACK_PRIORITY(fgFLOAT32);
}
void flgr_pstack_set_stack_priority_fgFLOAT64(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_MACRO_PSTACK_SET_STACK_PRIORITY(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! Set a the priority label field of FLGR_McStack structure
 *  @param stack : pointer on a FLGR_McStack structure
 *  @param priorityLabel : Vector or Scalar priority label
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr_pstack_set_stack_priority(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_DECLARE_FUNCTION;
  
  if((stack==NULL) || (priorityLabel==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  FLGR_DISPATCH_PROCEDURE(stack->type,flgr_pstack_set_stack_priority,stack,priorityLabel);
}





//////////////////////////////////////////////////////////////////
/*! Check if a stack correspond to a specific priority label
 *  @param stack : pointer on a FLGR_McStack structure
 *  @param priorityLabel : Vector or Scalar priority label
 *  @returns FLGR_TRUE or FLGR_FALSE
 */
//////////////////////////////////////////////////////////////////
int flgr_pstack_check_stack_priority(FLGR_McStack *stack, FLGR_Vector *priorityLabel) {
  FLGR_DECLARE_FUNCTION;
  
  return flgr_vector_equal(stack->priorityLabel, priorityLabel);
}



////////////////////////////////////////////////////////////////////////
// Macro for different types of flgr_pstack_create_stack
////////////////////////////////////////////////////////////////////////
#define PSTACK_CREATE_STACK(dtype,dtypename)				\
  FLGR_McStack *new = (FLGR_McStack *) flgr_malloc(sizeof(FLGR_McStack));	\
  FLGR_McStack *tmp;							\
  FLGR_VectorCompare fcompare = pstack->compareStackFunction;		\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  if(new==NULL) return NULL;						\
									\
  new->next = NULL;							\
  new->previous = NULL;							\
  new->top = NULL;							\
  new->compareStackFunction = fcompare;					\
  new->priorityLabel = flgr_vector_create(priorityLabel->spp,		\
					       priorityLabel->type);	\
  new->size = 0;							\
  new->type = dtypename;						\
									\
  flgr_pstack_set_stack_priority_##dtype(new,priorityLabel);		\
									\
  pstack->nbPriority++;							\
									\
  tmp = pstack->first;							\
									\
  if(tmp == NULL) {							\
    pstack->first = new;						\
    pstack->last = new;							\
									\
  }else {								\
									\
    if( (*fcompare)(tmp->priorityLabel,priorityLabel)==FLGR_TRUE ) {	\
      pstack->first = new;						\
      new->next = tmp;							\
      tmp->previous = new;						\
    }else {								\
      tmp = tmp->next;							\
      while(tmp != NULL) {						\
	if( (*fcompare)(tmp->priorityLabel,priorityLabel)==FLGR_TRUE) { \
	  new->next = tmp;						\
	  new->previous = tmp->previous;				\
	  tmp->previous->next = new;					\
	  tmp->previous = new;						\
	  return new;							\
	}								\
	tmp = tmp->next;						\
      }									\
									\
      if(tmp==NULL) {							\
	pstack->last->next = new;					\
	new->previous = pstack->last;					\
	pstack->last = new;						\
      }									\
									\
    }									\
									\
  }									\
									\
  return new

FLGR_McStack *flgr_pstack_create_stack_fgBIT(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  flgr_no_define_type_function(FLGR_BIT);
  return NULL;
}
FLGR_McStack *flgr_pstack_create_stack_fgUINT8(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_CREATE_STACK(fgUINT8,FLGR_UINT8);
}

FLGR_McStack *flgr_pstack_create_stack_fgUINT16(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_CREATE_STACK(fgUINT16,FLGR_UINT16);
}

FLGR_McStack *flgr_pstack_create_stack_fgUINT32(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_CREATE_STACK(fgUINT32,FLGR_UINT32);
}

FLGR_McStack *flgr_pstack_create_stack_fgINT8(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_CREATE_STACK(fgINT8,FLGR_INT8);
}

FLGR_McStack *flgr_pstack_create_stack_fgINT16(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_CREATE_STACK(fgINT16,FLGR_INT16);
}

FLGR_McStack *flgr_pstack_create_stack_fgINT32(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_CREATE_STACK(fgINT32,FLGR_INT32);
}

FLGR_McStack *flgr_pstack_create_stack_fgFLOAT32(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_CREATE_STACK(fgINT32,FLGR_FLOAT32);
}

FLGR_McStack *flgr_pstack_create_stack_fgFLOAT64(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_CREATE_STACK(fgINT32,FLGR_FLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! Create a stack for a specific priority label
 *  @param pstack : pointer on a FLGR_PStack structure
 *  @param priorityLabel : Vector priority label
 *  @returns a pointer to a FLGR_McStack
 */
//////////////////////////////////////////////////////////////////
FLGR_McStack *flgr_pstack_create_stack(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  FLGR_DECLARE_FUNCTION;
  
  if(pstack==NULL) {
    POST_ERROR("Null objects!\n");
    return NULL;
  }

  if(pstack->type==FLGR_UINT8) {
    return flgr_pstack_create_stack_fgUINT8( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_UINT16) {
    return flgr_pstack_create_stack_fgUINT16( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_UINT32) {
    return flgr_pstack_create_stack_fgUINT32( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_INT8) {
    return flgr_pstack_create_stack_fgINT8( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_INT16) {
    return flgr_pstack_create_stack_fgINT16( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_INT32) {
    return flgr_pstack_create_stack_fgINT32( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_FLOAT32) {
    return flgr_pstack_create_stack_fgFLOAT32( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_FLOAT64) {
    return flgr_pstack_create_stack_fgFLOAT64( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_BIT) {
    return flgr_pstack_create_stack_fgBIT( pstack,  priorityLabel );

  }else {
    POST_ERROR("type unknown!\n");
    return NULL;
  }

  return NULL;

}


//////////////////////////////////////////////////////////////////
/*! Find the first no empty stack in a Priority Stack
 *  @param pstack : pointer on a FLGR_PStack structure
 *  @returns a pointer to a FLGR_McStack
 */
//////////////////////////////////////////////////////////////////
FLGR_McStack *flgr_pstack_get_first_no_empty_stack(FLGR_PStack *pstack) {
  FLGR_McStack *tmp;

  FLGR_DECLARE_FUNCTION;
  
  if(pstack==NULL) {
    POST_ERROR("Null objects!\n");
    return NULL;
  }

  tmp = pstack->first;

  while(tmp != NULL) {
    if( tmp->size != 0 ) return tmp;
    tmp = tmp->next;
  }

  return NULL;
}

//////////////////////////////////////////////////////////////////
/*! Find the last no empty stack in a Priority Stack
 *  @param pstack : pointer on a FLGR_PStack structure
 *  @returns a pointer to a FLGR_McStack
 */
//////////////////////////////////////////////////////////////////
FLGR_McStack *flgr_pstack_get_last_no_empty_stack(FLGR_PStack *pstack) {
  FLGR_McStack *tmp;

  FLGR_DECLARE_FUNCTION;
  
  if(pstack==NULL) {
    POST_ERROR("Null objects!\n");
    return NULL;
  }

  tmp = pstack->last;

  while(tmp != NULL) {
    if( tmp->size != 0 ) return tmp;
    tmp = tmp->previous;
  }
  return NULL;
}

////////////////////////////////////////////////////////////////////////
// Macro for different types of flgr_pstack_get_stack
////////////////////////////////////////////////////////////////////////
#define PSTACK_GET_STACK(dtype)						\
  FLGR_McStack *tmp;							\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  tmp = pstack->first;							\
									\
  while(tmp != NULL) {							\
    if( flgr_pstack_check_stack_priority(tmp,priorityLabel)==FLGR_TRUE)	\
      return tmp;							\
    tmp = tmp->next;							\
  }									\
									\
  return NULL



FLGR_McStack *flgr_pstack_get_stack_fgBIT(FLGR_PStack *pstack,  FLGR_Vector *priorityLabel) {
  flgr_no_define_type_function(FLGR_BIT);
  return NULL;
}
FLGR_McStack *flgr_pstack_get_stack_fgUINT8(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_GET_STACK(fgUINT8);
}
FLGR_McStack *flgr_pstack_get_stack_fgUINT16(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_GET_STACK(fgUINT16);
}
FLGR_McStack *flgr_pstack_get_stack_fgUINT32(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_GET_STACK(fgUINT32);
}
FLGR_McStack *flgr_pstack_get_stack_fgINT8(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_GET_STACK(fgINT8);
}
FLGR_McStack *flgr_pstack_get_stack_fgINT16(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_GET_STACK(fgINT16);
}
FLGR_McStack *flgr_pstack_get_stack_fgINT32(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_GET_STACK(fgINT32);
}
FLGR_McStack *flgr_pstack_get_stack_fgFLOAT32(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_GET_STACK(fgFLOAT32);
}
FLGR_McStack *flgr_pstack_get_stack_fgFLOAT64(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  PSTACK_GET_STACK(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! Find a specific stack in a Priority Stack
 *  @param pstack : pointer on a FLGR_PStack structure
 *  @param priorityLabel : a pointer to an integer representing the stack priority label
 *  @returns a pointer to a FLGR_McStack
 */
//////////////////////////////////////////////////////////////////
FLGR_McStack *flgr_pstack_get_stack(FLGR_PStack *pstack, FLGR_Vector *priorityLabel) {
  FLGR_DECLARE_FUNCTION;
  
  if((pstack==NULL) || (priorityLabel==NULL)) {
    POST_ERROR("Null objects\n");
    return NULL;
  }

  if(pstack->type==FLGR_UINT8) {
    return flgr_pstack_get_stack_fgUINT8( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_UINT16) {
    return flgr_pstack_get_stack_fgUINT16( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_UINT32) {
    return flgr_pstack_get_stack_fgUINT32( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_INT8) {
    return flgr_pstack_get_stack_fgINT8( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_INT16) {
    return flgr_pstack_get_stack_fgINT16( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_INT32) {
    return flgr_pstack_get_stack_fgINT32( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_FLOAT32) {
    return flgr_pstack_get_stack_fgFLOAT32( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_FLOAT64) {
    return flgr_pstack_get_stack_fgFLOAT64( pstack,  priorityLabel );

  }else if(pstack->type==FLGR_BIT) {
    return flgr_pstack_get_stack_fgBIT( pstack,  priorityLabel );

  }else {
    POST_ERROR("type unknown!\n");
    return NULL;
  }

  return NULL;
}


FLGR_Vector *flgr_pstack_get_label_stack(FLGR_McStack *stack) {
  FLGR_DECLARE_FUNCTION;
  
  return stack->priorityLabel;
}



int flgr_pstack_is_last_stack(FLGR_McStack *stack) {
  FLGR_DECLARE_FUNCTION;
  
  return (stack->next==NULL);
}



//! @}
